home *** CD-ROM | disk | FTP | other *** search
- unit MonHelpU;
-
- interface
-
- uses
- Windows;
-
- const
- TraceBufSize = 8192;
-
- var
- wm_ClientLibNotify: Cardinal = 0;
- wm_MonitorNotify: Cardinal = 0;
-
- type
- TWMClientLibNotify = record
- Msg: Cardinal;
- Wnd: HWnd;
- Unused: Longint;
- Result: Longint;
- end;
-
- TWMMonitorNotify = record
- Msg: Cardinal;
- Wnd: HWnd;
- TraceValue: Integer;
- Result: Longint;
- end;
-
- var
- wm_UpdateClients: Cardinal = 0;
-
- type
- TWMUpdateClients = record
- Msg: Cardinal;
- TraceValue: Longint;
- Unused: Longint;
- Result: Longint;
- end;
-
- var
- wm_TraceMessage: Cardinal = 0;
-
- //These classes come from the IPCDemos sample project
- type
- { This is a generic class for all encapsulated WinAPI's which need to call
- CloseHandle when no longer needed. This code eliminates the need for
- 3 identical destructors in the TEvent, TMutex, and TSharedMem classes
- which are descended from this class. }
- THandledObject = class(TObject)
- protected
- FHandle: THandle;
- public
- destructor Destroy; override;
- property Handle: THandle read FHandle;
- end;
-
- { This class simplifies the process of creating a region of shared memory.
- In Win32, this is accomplished by using the CreateFileMapping and
- MapViewOfFile functions. }
- TSharedMem = class(THandledObject)
- private
- FName: string;
- FSize: Integer;
- FCreated: Boolean;
- FFileView: Pointer;
- public
- constructor Create(const Name: string; Size: Integer);
- destructor Destroy; override;
- property Name: string read FName;
- property Size: Integer read FSize;
- property Buffer: Pointer read FFileView;
- property Created: Boolean read FCreated;
- end;
-
- implementation
-
- uses
- SysUtils;
-
- { THandledObject }
-
- destructor THandledObject.Destroy;
- begin
- if FHandle <> 0 then
- CloseHandle(FHandle);
- end;
-
- { TSharedMem }
-
- constructor TSharedMem.Create(const Name: string; Size: Integer);
- begin
- try
- FName := Name;
- FSize := Size;
- { CreateFileMapping, when called with $FFFFFFFF for the hanlde value,
- creates a region of shared memory }
- FHandle := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0,
- Size, PChar(Name));
- if FHandle = 0 then abort;
- FCreated := GetLastError = 0;
- { We still need to map a pointer to the handle of the shared memory region }
- FFileView := MapViewOfFile(FHandle, FILE_MAP_WRITE, 0, 0, Size);
- if FFileView = nil then abort;
- except
- raise Exception.CreateFmt('Error creating shared memory %s (%d)', [Name, GetLastError]);
- end;
- end;
-
- destructor TSharedMem.Destroy;
- begin
- if FFileView <> nil then
- UnmapViewOfFile(FFileView);
- inherited Destroy;
- end;
-
- initialization
- wm_ClientLibNotify := RegisterWindowMessage('wm_ClientLibNotify');
- wm_MonitorNotify := RegisterWindowMessage('wm_MonitorNotify');
- wm_UpdateClients := RegisterWindowMessage('wm_UpdateClients');
- wm_TraceMessage := RegisterWindowMessage('wm_TraceMessage');
- end.
-